package collection_homework;

import javax.sql.rowset.FilteredRowSet;
import java.util.ArrayList;
import java.util.List;

public class ListDemo_homework {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println(list);

        String e = list.get(3);
        System.out.println(e);
        for (int i = 0; i < list.size(); i++){
            System.out.println(list.get(i));
        }
        System.out.println("----------------------");

        list.set(2,"seven");
        System.out.println(list);

        list.add(2,"six");
        System.out.println(list);
        list.add(6,"eight");
        System.out.println(list);
        list.remove(2);
        System.out.println(list);

        //子集
        List<Integer> list1 = new ArrayList<>();
        for (int i = 0; i < 10; i++){
            list1.add(i*10);
        }
        System.out.println(list1);

        List<Integer> subList = list1.subList(2, 6);
        System.out.println(subList);

        for (int i = 0; i < subList.size(); i++){
            subList.set(i,subList.get(i)*10);
        }
        System.out.println(subList);
        System.out.println(list1);

        list1.set(2,10000);
        System.out.println(list1);
        System.out.println(subList);

        list1.remove(0);
        System.out.println(list1);
        //System.out.println(subList);



        //数组转换为集合
        String[] array = {"one","two","three","four","five"};
        List<String> list2 = new ArrayList<>();
        for (String s : array){
            list2.add(s);
        }
        System.out.println(list2);


    }
}
